package com.hsytech.dijiebao.person.activity;

import java.util.ArrayList;
import java.util.List;

import com.hsytech.dijiebao.R;
import com.hsytech.dijiebao.base.BaseActivity;
import com.hsytech.dijiebao.person.fragment.CollectHotelFrament;
import com.hsytech.dijiebao.person.fragment.CollectTaxilFrament;
import com.hsytech.dijiebao.view.PagerSlidingTabStrip;

import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

public class CollectActivity extends BaseActivity {
	private View root;
	private ViewPager activity_repair_viewpager;
	private CollectHotelFrament hotleFrament;
	private CollectTaxilFrament taxiFrament;
	private List<Fragment> myFragmentList;
	private ImageButton top_back_btn;
	private Button bar_right_top_btn;
	private TextView bar_title_tv;
	private final Handler handler = new Handler();
	private ImageView new_city00;
	private PagerSlidingTabStrip tabs;
	private MyPagerAdapter adapter;
	private DisplayMetrics dm;
	private Drawable oldBackground = null;
	private int currentColor = 0xff66ccff;
	private int afterColor = 0xff66ccff;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		dm = getResources().getDisplayMetrics();
		setContentView(R.layout.activity_release_main);
		initTitle();
		initBody();
	}

	private void initTitle() {
		bar_right_top_btn = (Button) findViewById(R.id.bar_right_top_btn);
		bar_right_top_btn.setVisibility(View.GONE);

		top_back_btn = (ImageButton) findViewById(R.id.top_back_btn);
		top_back_btn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				finish();
			}
		});
		// bar_right_top_btn = (Button)
		// root.findViewById(R.id.bar_right_top_btn);
		// bar_right_top_btn.setVisibility(View.GONE);
		bar_title_tv = (TextView) findViewById(R.id.bar_title_tv);
		bar_title_tv.setText("�ҵ��ղ�");
	}

	private void setTabsValue() {

		// ����Tab���Զ��������Ļ��
		tabs.setShouldExpand(true);
		// ����Tab�ķָ�����͸����
		tabs.setDividerColor(Color.TRANSPARENT);
		// ����Tab�ײ��ߵĸ߶�
		tabs.setUnderlineHeight((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, dm));
		// ����Tab Indicator�ĸ߶�
		tabs.setIndicatorHeight((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, dm));
		// ����Tab�������ֵĴ�С
		tabs.setTextSize((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 16, dm));
		// ����Tab Indicator����ɫ
		tabs.setIndicatorColor(currentColor);
		// ����ѡ��Tab���ֵ���ɫ (�������Զ����һ������)
		tabs.setSelectedTextColor(afterColor);
		// ȡ�����Tabʱ�ı���ɫ
		tabs.setTabBackground(0);

		tabs.setTextColor(getResources().getColor(R.color.gary_first));

	}

	private void initBody() {
		myFragmentList = new ArrayList<Fragment>();
		hotleFrament = new CollectHotelFrament();
		taxiFrament = new CollectTaxilFrament();

		myFragmentList.add(hotleFrament);
		myFragmentList.add(taxiFrament);
		activity_repair_viewpager = (ViewPager) findViewById(R.id.activity_repair_viewpager);
		activity_repair_viewpager.setCurrentItem(0);
		tabs = (PagerSlidingTabStrip) findViewById(R.id.tabs);
		setTabsValue();
		adapter = new MyPagerAdapter(getSupportFragmentManager(), myFragmentList);

		activity_repair_viewpager.setAdapter(adapter);

		final int pageMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4,
				getResources().getDisplayMetrics());
		activity_repair_viewpager.setPageMargin(pageMargin);

		tabs.setViewPager(activity_repair_viewpager);
	}

	public class MyPagerAdapter extends FragmentPagerAdapter {

		private final String[] TITLES = { "�Ƶ�", "�⳵" };
		private List<Fragment> myFragmentsList;

		public MyPagerAdapter(FragmentManager fragmentmanager, List<Fragment> list) {
			super(fragmentmanager);
			myFragmentsList = list;
		}

		public int getItemPosition(Object obj) {
			return super.getItemPosition(obj);
		}

		public MyPagerAdapter(FragmentManager fm) {
			super(fm);
		}

		public int getCount() {
			return myFragmentsList.size();
		}

		public Fragment getItem(int i) {
			return (Fragment) myFragmentsList.get(i);
		}

		@Override
		public CharSequence getPageTitle(int position) {
			return TITLES[position];
		}

	}
}
